<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: Update Chart Axis</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <script src="../../build/yui/yui-min.js"></script>
</head>
<body>

<div id="doc">
    <h1>Example: Update Chart Axis</h1>

    

    <div class="yui3-g">
        <div id="main" class="yui3-u">
            <div class="content"><style scoped>
#mychart {
    margin:10px 10px 10px 10px;
    width:90%;
    max-width: 800px;
    height:400px;
}

.fields label {
    font-weight:bold;
    display:block;
    float:left;
    width:8em;
}

.fields {
    border-top:1px solid #aaa;
    padding:10px;
}
</style>
<div class="intro">
<p>This example shows how to access <code>Chart</code> instance's value axis after the <code>Chart</code> has rendered.</p>
</div>
<div class="example">
<div id="mychart"></div>
<div class="fields">
    <p>
        <label for="axisSelector">axis:</label>
        <select name="axisSelector" id="axisSelector">
            <option value="dateRange">dateRange</option>
            <option value="financials">financials</option>
        </select>
    </p>
    <p>
        <label for="color">color:</label>
        <input type="text" name="color" id="color" />
    </p>
    <p>
        <label for="rotation">rotation:</label>
        <input type="text" name="rotation" id="rotation" />
    </p>
    <p>
        <button type="button" class="action" id="updateAxis">Update Axis</button>
    </p>
</div>
<script type="text/javascript">
(function() {
    YUI().use('escape', 'charts', function (Y) 
    { 
        //dataProvider source
        var myDataValues = [ 
            {date:"1/1/2010", miscellaneous:2000, expenses:3700, revenue:2200}, 
            {date:"2/1/2010", miscellaneous:5000, expenses:9100, revenue:100}, 
            {date:"3/1/2010", miscellaneous:4000, expenses:1900, revenue:1500}, 
            {date:"4/1/2010", miscellaneous:3000, expenses:3900, revenue:2800}, 
            {date:"5/1/2010", miscellaneous:500, expenses:7000, revenue:2650},
            {date:"6/1/2010", miscellaneous:3000, expenses:4700, revenue:1200} 
        ];
        
        //Define our axes for the chart.
        var myAxes = {
            financials:{
                keys:["miscellaneous", "revenue", "expenses"],
                position:"right",
                type:"numeric",
                styles:{
                    majorTicks:{
                        display: "none"
                    }
                }
            },
            dateRange:{
                keys:["date"],
                position:"bottom",
                type:"category",
                styles:{
                    majorTicks:{
                        display: "none"
                    },
                    label: {
                        rotation:-45,
                        margin:{top:5}
                    }
                }
            }
        };

        //instantiate the chart
        var myChart = new Y.Chart({
                            type:"column",
                            categoryKey:"date",
                            dataProvider:myDataValues, 
                            axes:myAxes, 
                            horizontalGridlines: true,
                            verticalGridlines: true,
                            render:"#mychart"
                        });
        
        //Click handler
        Y.on("click", function(e) {
            var axisName = Y.one("#axisSelector").get("value"),
                rotation = parseFloat(Y.one("#rotation").get("value")),
                color = Y.Escape.html(Y.one("#color").get("value")),
                label = null,
                axis;
            if(axisName)
            {
                axis = myChart.getAxisByKey(axisName);
                if(!isNaN(rotation))
                {
                    label = {rotation:rotation};
                }
                if(color)
                {
                    if(!label)
                    {
                        label = {};
                    }
                    label.color = color;
                }
                if(label)
                {
                    axis.set("styles", {label:label});
                }
            }
       }, "#updateAxis");
    });
})();
</script>

</div>
<h3>Access and Update a <code>Chart</code> Instance's Axis.</h3>


<p>Often times, you will need to update a chart after it has been rendered. This example demonstrates how to access and update an axis. Specifically, we'll update the rotation and color of 
the axis labels.</p>
<p>A <code>Chart</code> instance's axes can be accessed through the <code>getAxisByKey</code> method. This method takes the axis' key identifier as an argument. If you have explicitly set your
axis through the <code>axes</code> attribute, you will know the key identifier. If not, the default key identifier for the value axis is "values" and the default key identifier for the category
axis is <code>category</code>. Once you have a reference for the axis, you can update all of its public attributes.</p>

<pre class="code prettyprint">YUI().use(&#x27;charts&#x27;, function (Y) 
{ 
    &#x2F;&#x2F;dataProvider source
    var myDataValues = [ 
        {date:&quot;1&#x2F;1&#x2F;2010&quot;, miscellaneous:2000, expenses:3700, revenue:2200}, 
        {date:&quot;2&#x2F;1&#x2F;2010&quot;, miscellaneous:5000, expenses:9100, revenue:100}, 
        {date:&quot;3&#x2F;1&#x2F;2010&quot;, miscellaneous:4000, expenses:1900, revenue:1500}, 
        {date:&quot;4&#x2F;1&#x2F;2010&quot;, miscellaneous:3000, expenses:3900, revenue:2800}, 
        {date:&quot;5&#x2F;1&#x2F;2010&quot;, miscellaneous:500, expenses:7000, revenue:2650},
        {date:&quot;6&#x2F;1&#x2F;2010&quot;, miscellaneous:3000, expenses:4700, revenue:1200} 
    ];
    
    &#x2F;&#x2F;Define our axes for the chart.
    var myAxes = {
        financials:{
            keys:[&quot;miscellaneous&quot;, &quot;revenue&quot;, &quot;expenses&quot;],
            position:&quot;right&quot;,
            type:&quot;numeric&quot;,
            styles:{
                majorTicks:{
                    display: &quot;none&quot;
                }
            }
        },
        dateRange:{
            keys:[&quot;date&quot;],
            position:&quot;bottom&quot;,
            type:&quot;category&quot;,
            styles:{
                majorTicks:{
                    display: &quot;none&quot;
                },
                label: {
                    rotation:-45,
                    margin:{top:5}
                }
            }
        }
    };

    &#x2F;&#x2F;instantiate the chart
    var myChart = new Y.Chart({
                        type:&quot;column&quot;,
                        categoryKey:&quot;date&quot;,
                        dataProvider:myDataValues, 
                        axes:myAxes, 
                        horizontalGridlines: true,
                        verticalGridlines: true,
                        render:&quot;#mychart&quot;
                    });

    &#x2F;&#x2F;Click handler
    Y.on(&quot;click&quot;, function(e) {
        var axisName = Y.one(&quot;#axisSelector&quot;).get(&quot;value&quot;),
            rotation = parseFloat(Y.one(&quot;#rotation&quot;).get(&quot;value&quot;)),
            color = Y.Escape.html(Y.one(&quot;#color&quot;).get(&quot;value&quot;)),
            label = null,
            axis;
        if(axisName)
        {
            axis = myChart.getAxisByKey(axisName);
            if(!isNaN(rotation))
            {
                label = {rotation:rotation};
            }
            if(color)
            {
                if(!label)
                {
                    label = {};
                }
                label.color = color;
            }
            if(label)
            {
                axis.set(&quot;styles&quot;, {label:label});
            }
        }
   }, &quot;#updateAxis&quot;);
});</pre>

</div>
        </div>

        <div id="sidebar" class="yui3-u">
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                                    <li data-description="Shows how to use Charts to create a basic chart.">
                                        <a href="charts-simple.html">Basic Charts Implementation</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to create a chart with multiple series.">
                                        <a href="charts-multiseries.html">Chart with Multiple Series</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to create a column chart with multiple series.">
                                        <a href="charts-column.html">Specify Chart Type</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to create a column chart with a stacked numeric axis.">
                                        <a href="charts-stackedcolumn.html">Create Stacked Chart</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to create a chart with a time axis.">
                                        <a href="charts-timeaxis.html">Create a Chart with a Time Axis</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to add gridlines to a chart.">
                                        <a href="charts-gridlines.html">Add Gridlines to a Chart</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to create a chart with planar based events.">
                                        <a href="charts-stackedarea.html">Create a Stacked Area Chart with Planar Based Events</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to use a chart&#x27;s styles attribute to customize a chart.">
                                        <a href="charts-globalstyles.html">Customize a Chart</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to customize the default tooltip of a chart.">
                                        <a href="charts-customizedtooltip.html">Customize a Chart&#x27;s Tooltip</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to explicitly define the axes and series for a chart.">
                                        <a href="charts-objectstyles.html">Define a Chart&#x27;s Axes and Series</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to use charts to create a pie chart.">
                                        <a href="charts-pie.html">Pie Chart</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to create a chart with multiple value axes.">
                                        <a href="charts-dualaxes.html">Dual Axes Chart</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to access a chart instance&#x27;s value axis after the chart has rendered.">
                                        <a href="charts-axisupdate.html">Update Chart Axis</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Shows how to access a chart instance&#x27;s seriesCollection after the chart has rendered.">
                                        <a href="charts-seriesupdate.html">Update Chart Series</a>
                                    </li>
                                
                            
                        </ul>
                    </div>
                </div>
            

            
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

</body>
</html>
